import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP

from lib.webui import  *

class c73307:
    name = '验证修改密码时的无效长度验证功能-73307' # 测试用例名字

# 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        wd = open_browser()
        mgr_login(wd)

    #清除方法
    def teardown(self):
        wd = get_global_webdriver()
        wd.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()

        time.sleep(2)
        STEP(2, "修改密码长度为1")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("1")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("1")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        short_error = driver.find_element(By.CSS_SELECTOR, ".el-form-item__error").text
        expect_short = "密码不能少于六位"
        CHECK_POINT("提示信息是否一致", short_error == expect_short)
        driver.find_element(By.CSS_SELECTOR, ".el-dialog__wrapper:nth-child(2) .el-dialog__close").click()

        time.sleep(2)
        STEP(3, "修改密码长度为5")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("a123.")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("a123.")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        short_error1 = driver.find_element(By.CSS_SELECTOR, ".el-form-item__error").text
        expect_short1 = "密码不能少于六位"
        CHECK_POINT("提示信息是否一致", short_error1 == expect_short1)
        driver.find_element(By.CSS_SELECTOR, ".el-dialog__wrapper:nth-child(2) .el-dialog__close").click()

        time.sleep(2)
        STEP(3, "修改密码长度为13")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("a1.a1.a1.a1.a")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("a1.a1.a1.a1.a")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        short_error2 = driver.find_element(By.CSS_SELECTOR,
        "div.el-form-item:nth-child(2) > div:nth-child(2) > div:nth-child(2)"
                                          ).text
        expect_short2 = "密码不能大于12位"
        CHECK_POINT("提示信息是否一致", short_error2 == expect_short2)
        driver.find_element(By.CSS_SELECTOR, ".el-dialog__wrapper:nth-child(2) .el-dialog__close").click()

